<?php

defined('MYLITS') ? '' : exit('No direct script access allowed');

/**
 * @version     1.0.0
 * @package     mylits engine
 * @license     GNU General Public License version 3
 * @author      Arfan Fudyartanto D N <arfan@mylits.com> - http://engine.mylits.com
 */
class menusModel extends Mylits_Model {

    function __construct() {
        parent::__construct();
        $this->setConnectionNumber(0);
        $this->setSqlFile('menus');
    }
    
    public function getMenuList(){
        $query = $this->openQuery('get_menu_list');
        return $this->runQuery($query);;
    }

    public function getMenuItemList($menuId, $langCode, $parent = NULL) {
        $query = $this->openQuery('get_menu_item_list', array($menuId, $langCode));
        $search = '';
        if (empty($parent)) {
            $search .= 'AND ISNULL(b.`core_menus_items_parent_id`)';
        } else {
            $search .= 'AND b.`core_menus_items_parent_id` = ' . $parent;
        }
        $query = str_replace('--search--', $search, $query);
        $result = $this->runQuery($query);
        foreach ($result as $key => $menuItem) {
            $child = $this->getMenuItemList($menuId, $langCode, $menuItem['id']);
            if (!empty($child)) {
                $result[$key]['child'] = $child;
            }
        }
        return $result;
    }

}

?>
